package com.easy.controller;

import com.easy.bean.Donation;
import com.easy.service.DonationService;
import com.easy.util.Page;
import com.easy.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("donation")
public class
DonationController {
    @Autowired
    DonationService donationService;
    @PostMapping
    public Result add(@RequestBody Donation donation) {
        Object obj = donationService.add(donation);
        return Result.success(obj);
     }

    @PutMapping
    public Result edit(@RequestBody Donation donation) {
        Object obj = donationService.edit(donation);
        return Result.success(obj);
    }
    @DeleteMapping("{donation_id}")
    public Result del(@PathVariable("donation_id") Integer id){
        Object obj = donationService.del(id);
        return Result.success(obj);
    }
    @GetMapping("{donation_id}")
    public Result one(@PathVariable("donation_id") Integer id){
        Object obj = donationService.one(id);
        return Result.success(obj);
    }
    @GetMapping("all")
    public Result all(Donation donation){
        Object obj = donationService.all(donation);
        return Result.success(obj);
    }
    @GetMapping("page")
    public Result page(Page page, Donation donation){
        //查询一共有多少条数据
        //查询当前页要显示的数据
        //将以上数据封装到page对象中
        donationService.page(page,donation);
        //返回page对象
        return Result.success(page);
    }
}
